using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Text;

namespace Data_Access_Tier
{
	public class HRM_PROCESS_ACCIDENTData : DatabaseObjectBase
	{
		public HRM_PROCESS_ACCIDENTData()
		{
			Initialize(true);
		}
		public HRM_PROCESS_ACCIDENTData(Boolean newConnection)
		{
			Initialize(newConnection);
		}

		public Int32 HRM_PROCESS_ACCIDENT_Insert(Guid AccidentID, String EmployeeCode, String AccidentName, String Reason, DateTime DateOccured, String Location, String Description, String Damage, String Injury, String Allowance, String Note)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.InsertCommand = new SqlCommand("HRM_PROCESS_ACCIDENT_Insert");
				_dbadapter.InsertCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.InsertCommand.Connection = _dbconn;
				_trans = _dbconn.BeginTransaction();
				_dbadapter.InsertCommand.Transaction = _trans;
				_dbadapter.InsertCommand.Parameters.Clear();
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@AccidentID", SqlDbType.UniqueIdentifier));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@EmployeeCode", SqlDbType.VarChar, 20));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@AccidentName", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Reason", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@DateOccured", SqlDbType.DateTime));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Location", SqlDbType.NVarChar, 155));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Description", SqlDbType.NVarChar, 1000));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Damage", SqlDbType.NVarChar, 1000));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Injury", SqlDbType.NVarChar, 1000));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Allowance", SqlDbType.NVarChar, 1000));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Note", SqlDbType.NVarChar, 1000));
				_dbadapter.InsertCommand.Prepare();
				SqlGuid AccidentIDSQL = AccidentID;
				_dbadapter.InsertCommand.Parameters["@AccidentID"].Value = AccidentIDSQL;
				SqlString EmployeeCodeSQL = EmployeeCode;
				_dbadapter.InsertCommand.Parameters["@EmployeeCode"].Value = EmployeeCodeSQL;
				SqlString AccidentNameSQL = AccidentName;
				_dbadapter.InsertCommand.Parameters["@AccidentName"].Value = AccidentNameSQL;
				SqlString ReasonSQL = Reason;
				_dbadapter.InsertCommand.Parameters["@Reason"].Value = ReasonSQL;
				SqlDateTime DateOccuredSQL = SqlDateTime.Null;
				if (DateOccured > DateTime.MinValue)
				{
					try
					{
						DateOccuredSQL = DateOccured;
					}
					catch (Exception eDateOccured)
					{
						String DateOccuredMessage = eDateOccured.Message;
						DateOccuredSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.InsertCommand.Parameters["@DateOccured"].Value = DateOccuredSQL;
				SqlString LocationSQL = Location;
				_dbadapter.InsertCommand.Parameters["@Location"].Value = LocationSQL;
				SqlString DescriptionSQL = Description;
				_dbadapter.InsertCommand.Parameters["@Description"].Value = DescriptionSQL;
				SqlString DamageSQL = Damage;
				_dbadapter.InsertCommand.Parameters["@Damage"].Value = DamageSQL;
				SqlString InjurySQL = Injury;
				_dbadapter.InsertCommand.Parameters["@Injury"].Value = InjurySQL;
				SqlString AllowanceSQL = Allowance;
				_dbadapter.InsertCommand.Parameters["@Allowance"].Value = AllowanceSQL;
				SqlString NoteSQL = Note;
				_dbadapter.InsertCommand.Parameters["@Note"].Value = NoteSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.InsertCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_PROCESS_ACCIDENT_Insert: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_PROCESS_ACCIDENT_Insert: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.InsertCommand != null)
					_dbadapter.InsertCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_PROCESS_ACCIDENT_Update(Guid AccidentID, String EmployeeCode, String AccidentName, String Reason, DateTime DateOccured, String Location, String Description, String Damage, String Injury, String Allowance, String Note)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_PROCESS_ACCIDENT_Update");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@AccidentID", SqlDbType.UniqueIdentifier));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@EmployeeCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@AccidentName", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Reason", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@DateOccured", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Location", SqlDbType.NVarChar, 155));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Description", SqlDbType.NVarChar, 1000));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Damage", SqlDbType.NVarChar, 1000));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Injury", SqlDbType.NVarChar, 1000));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Allowance", SqlDbType.NVarChar, 1000));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Note", SqlDbType.NVarChar, 1000));
				_dbadapter.UpdateCommand.Prepare();
				SqlGuid AccidentIDSQL = AccidentID;
				_dbadapter.UpdateCommand.Parameters["@AccidentID"].Value = AccidentIDSQL;
				SqlString EmployeeCodeSQL = EmployeeCode;
				_dbadapter.UpdateCommand.Parameters["@EmployeeCode"].Value = EmployeeCodeSQL;
				SqlString AccidentNameSQL = AccidentName;
				_dbadapter.UpdateCommand.Parameters["@AccidentName"].Value = AccidentNameSQL;
				SqlString ReasonSQL = Reason;
				_dbadapter.UpdateCommand.Parameters["@Reason"].Value = ReasonSQL;
				SqlDateTime DateOccuredSQL = SqlDateTime.Null;
				if (DateOccured > DateTime.MinValue)
				{
					try
					{
						DateOccuredSQL = DateOccured;
					}
					catch (Exception eDateOccured)
					{
						String DateOccuredMessage = eDateOccured.Message;
						DateOccuredSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@DateOccured"].Value = DateOccuredSQL;
				SqlString LocationSQL = Location;
				_dbadapter.UpdateCommand.Parameters["@Location"].Value = LocationSQL;
				SqlString DescriptionSQL = Description;
				_dbadapter.UpdateCommand.Parameters["@Description"].Value = DescriptionSQL;
				SqlString DamageSQL = Damage;
				_dbadapter.UpdateCommand.Parameters["@Damage"].Value = DamageSQL;
				SqlString InjurySQL = Injury;
				_dbadapter.UpdateCommand.Parameters["@Injury"].Value = InjurySQL;
				SqlString AllowanceSQL = Allowance;
				_dbadapter.UpdateCommand.Parameters["@Allowance"].Value = AllowanceSQL;
				SqlString NoteSQL = Note;
				_dbadapter.UpdateCommand.Parameters["@Note"].Value = NoteSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_PROCESS_ACCIDENT_Update: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_PROCESS_ACCIDENT_Update: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_PROCESS_ACCIDENT_Disable(Guid AccidentID, ref Boolean Enabled)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_PROCESS_ACCIDENT_Disable");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@AccidentID", SqlDbType.UniqueIdentifier));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@enabled", SqlDbType.Bit));
				_dbadapter.UpdateCommand.Prepare();
				SqlGuid AccidentIDSQL = AccidentID;
				_dbadapter.UpdateCommand.Parameters["@AccidentID"].Value = AccidentIDSQL;
				_dbadapter.UpdateCommand.Parameters["@enabled"].Direction = ParameterDirection.Output;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_PROCESS_ACCIDENT_Disable: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_PROCESS_ACCIDENT_Disable: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_PROCESS_ACCIDENT_Delete(Guid AccidentID)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.DeleteCommand = new SqlCommand("HRM_PROCESS_ACCIDENT_Delete");
				_dbadapter.DeleteCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.DeleteCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.DeleteCommand.Transaction = _trans;

				_dbadapter.DeleteCommand.Parameters.Clear();
				_dbadapter.DeleteCommand.Parameters.Add(new SqlParameter("@AccidentID", SqlDbType.UniqueIdentifier));
				_dbadapter.DeleteCommand.Prepare();
				SqlGuid AccidentIDSQL = AccidentID;
				_dbadapter.DeleteCommand.Parameters["@AccidentID"].Value = AccidentIDSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.DeleteCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_PROCESS_ACCIDENT_Delete: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_PROCESS_ACCIDENT_Delete: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.DeleteCommand != null)
					_dbadapter.DeleteCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_PROCESS_ACCIDENT_Save(Guid AccidentID, String EmployeeCode, String AccidentName, String Reason, DateTime DateOccured, String Location, String Description, String Damage, String Injury, String Allowance, String Note)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_PROCESS_ACCIDENT_Save");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@AccidentID", SqlDbType.UniqueIdentifier));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@EmployeeCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@AccidentName", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Reason", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@DateOccured", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Location", SqlDbType.NVarChar, 155));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Description", SqlDbType.NVarChar, 1000));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Damage", SqlDbType.NVarChar, 1000));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Injury", SqlDbType.NVarChar, 1000));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Allowance", SqlDbType.NVarChar, 1000));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Note", SqlDbType.NVarChar, 1000));
				_dbadapter.UpdateCommand.Prepare();
				SqlGuid AccidentIDSQL = AccidentID;
				_dbadapter.UpdateCommand.Parameters["@AccidentID"].Value = AccidentIDSQL;
				SqlString EmployeeCodeSQL = EmployeeCode;
				_dbadapter.UpdateCommand.Parameters["@EmployeeCode"].Value = EmployeeCodeSQL;
				SqlString AccidentNameSQL = AccidentName;
				_dbadapter.UpdateCommand.Parameters["@AccidentName"].Value = AccidentNameSQL;
				SqlString ReasonSQL = Reason;
				_dbadapter.UpdateCommand.Parameters["@Reason"].Value = ReasonSQL;
				SqlDateTime DateOccuredSQL = SqlDateTime.Null;
				if (DateOccured > DateTime.MinValue)
				{
					try
					{
						DateOccuredSQL = DateOccured;
					}
					catch (Exception eDateOccured)
					{
						String DateOccuredMessage = eDateOccured.Message;
						DateOccuredSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@DateOccured"].Value = DateOccuredSQL;
				SqlString LocationSQL = Location;
				_dbadapter.UpdateCommand.Parameters["@Location"].Value = LocationSQL;
				SqlString DescriptionSQL = Description;
				_dbadapter.UpdateCommand.Parameters["@Description"].Value = DescriptionSQL;
				SqlString DamageSQL = Damage;
				_dbadapter.UpdateCommand.Parameters["@Damage"].Value = DamageSQL;
				SqlString InjurySQL = Injury;
				_dbadapter.UpdateCommand.Parameters["@Injury"].Value = InjurySQL;
				SqlString AllowanceSQL = Allowance;
				_dbadapter.UpdateCommand.Parameters["@Allowance"].Value = AllowanceSQL;
				SqlString NoteSQL = Note;
				_dbadapter.UpdateCommand.Parameters["@Note"].Value = NoteSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_PROCESS_ACCIDENT_Save: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_PROCESS_ACCIDENT_Save: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public DataSet HRM_PROCESS_ACCIDENT_GetList()
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.SelectCommand = new SqlCommand("HRM_PROCESS_ACCIDENT_GetList");
				_dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.SelectCommand.Connection = _dbconn;
				_dbadapter.SelectCommand.Parameters.Clear();
				_dbadapter.SelectCommand.Prepare();
				_dbadapter.Fill(_data);

				return _data;
			}
			catch (SqlException e)
			{
				throw new Exception("SQL Error: HRM_PROCESS_ACCIDENT_GetList: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.SelectCommand != null)
					_dbadapter.SelectCommand.Dispose();
				CloseConnection();
			}
		}
		public DataSet HRM_PROCESS_ACCIDENT_Get(Guid AccidentID)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.SelectCommand = new SqlCommand("HRM_PROCESS_ACCIDENT_Get");
				_dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.SelectCommand.Connection = _dbconn;
				_dbadapter.SelectCommand.Parameters.Clear();
				_dbadapter.SelectCommand.Parameters.Add(new SqlParameter("@AccidentID", SqlDbType.UniqueIdentifier));
				_dbadapter.SelectCommand.Prepare();
				SqlGuid AccidentIDSQL = AccidentID;
				_dbadapter.SelectCommand.Parameters["@AccidentID"].Value = AccidentIDSQL;
				_dbadapter.Fill(_data);

				return _data;
			}
			catch (SqlException e)
			{
				throw new Exception("SQL Error: HRM_PROCESS_ACCIDENT_Get: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.SelectCommand != null)
					_dbadapter.SelectCommand.Dispose();
				CloseConnection();
			}
		}
	}
}
